const smtp = require('smtp-protocol');
const simpleParser = require('mailparser').simpleParser;
const axios = require('axios')
const server = smtp.createServer(function (req) {
    req.on('greeting', function (to, ack) {
        ack.accept();
    });
    req.on('from', function (to, ack) {
        ack.accept();
    });
    req.on('to', function (to, ack) {
        //   filter(to, ack);//过滤smtp请求    
        ack.accept();
    });
    req.on('message', function (stream, ack) {
        simpleParser(stream)
            .then(parsed => {
                axios.post('http://calender-serve.linkcn.club/',parsed)
            })
            .catch(err => { 
                console.error(err)
            });
        ack.accept();
    });
});
server.listen(25);
console.log('starting mail server listen port 25.')